import JSEncrypt from "jsencrypt/bin/jsencrypt.min";

// 密钥对生成 http://web.chacuo.net/netrsakeypair

// const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKoR8mX0rGKLqzcWmOzbfj64K8ZIgOdH\n' +
//   'nzkXSOVOZbFu/TJhZ7rFAN+eaGkl3C4buccQd/EjEsj9ir7ijT7h96MCAwEAAQ=='
const publicKey =
  "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCqt5xp4sp4lWpw8w0KiUAM2fSmPDZRQN2e62vL2zx7znENUXCTdBdGqypIEF9OFtuXlMzdaQ/+XdE1l8SpF9S0FfGReN+PYXZ7eUH6DUvy4QxlleNm+pe5WIevqn+HBXSMotYcNxMsloaAEsCm+3ko0MhOoP+fWQbYhvgTaMRkrwIDAQAB";
const privateKey =
  "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAKq3nGniyniVanDzDQqJQAzZ9KY8NlFA3Z7ra8vbPHvOcQ1RcJN0F0arKkgQX04W25eUzN1pD/5d0TWXxKkX1LQV8ZF4349hdnt5QfoNS/LhDGWV42b6l7lYh6+qf4cFdIyi1hw3EyyWhoASwKb7eSjQyE6g/59ZBtiG+BNoxGSvAgMBAAECgYANXvYsQOwUx7cfg5nY4mkW2JdV0c97S7ZP9SZrQA+brs6h+Wf01JniGhPkswuT5Sxr0ea9zLXI+XYiWXG4wLoTA4MvX62XmFxuJjrokK4m04r3ToJ2w3z1DR+UdU1VpAyK+pSgD0TTuwY5SSfsfIkHfw/KOgqkWfD5+oC7N+t6kQJBAPn84f/JgnzJjOFUbE4UoNinSigCNGNEGbYDpFwXeUeRfQX1cz9NRfy0pPyf+CWcLsbUDnN+MYtft5qdczVh9/kCQQCu0q1vXM6aj/rhFtvrRLYLTEcYNWuMhJ9IHSBb1S3w2S9Gt1U8WsXXamcpaw/dt6t72cDoyWBofklL+ckdQXvnAkEAhPjKjfB2BEKBOWpaob2/QP7bJyTlENgshPCzAHlL/ZGZ2w2QW9+SlrTP/cBpkjfdec1aUnyRhf1IAGo32fFeoQJAF9Dbj7A09RloNAHJM+PIaQGbLdEZNatbh5dwMRJ5j7YGmrufAPncudvk8d+D6dB7rAOeJBhK6fFKSu9cVn/1QQJBAKBh/rPstRIMpVlVcHHzJa+KaKdjYf1/DFhiR6dENw4ByWcLnGvpAfKCmti1zZVauW0GYUiGU/WuWf5AD/UdFNY=";

// 加密
export function encrypt(txt) {
  const encryptor = new JSEncrypt();
  encryptor.setPublicKey(publicKey); // 设置公钥
  return encryptor.encrypt(txt); // 对数据进行加密
}

// 解密
export function decrypt(txt) {
  const encryptor = new JSEncrypt();
  encryptor.setPrivateKey(privateKey); // 设置私钥
  return encryptor.decrypt(txt); // 对数据进行解密
}
